﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    // NOT DONE - not working
	[Serializable]
	[DataContract]
	public class GlobalMonitor
	{
		[field: NonSerialized]
		public event EventHandler<ObjectEventArgs<Exception>> ExceptionOccurred;

		public static GlobalMonitor _instance;
		public static GlobalMonitor GetInstance()
		{

			if (_instance == null)
			{
				if (Interlocked.CompareExchange<GlobalMonitor>(ref _instance, new GlobalMonitor(), null) == null)
				{
					_instance.ExceptionOccurred += new EventHandler<ObjectEventArgs<Exception>>(_instance._instance_ExceptionOccurred);
				}
			}

			return _instance;
		}

		protected void _instance_ExceptionOccurred(object sender, ObjectEventArgs<Exception> e)
		{
			if (ExceptionOccurred != null)
				ExceptionOccurred(this, e);
		}

		public long EventsExecuted
		{
			get { return Globals.SchedulingEngine.WorkItemsExecuted; }
		}

		public ISupportsCount[] WorkItemQueueCounts { get { return Globals.SchedulingEngine.WorkItemQueueCounts; } }
		public DateTime CurrentTime { get { return Globals.TimeFlow.CurrentTime; } }

		public int MapMin_X
		{
			get { return WorldMap.Instance.World.GetLowerBound(0); }
		}

		public int MapMin_Y
		{
			get { return WorldMap.Instance.World.GetLowerBound(1); }
		}

		public int MapMin_Z
		{
			get { return WorldMap.Instance.World.GetLowerBound(2); }
		}

		public int MapMax_X
		{
			get { return WorldMap.Instance.World.GetUpperBound(0); }
		}

		public int MapMax_Y
		{
			get { return WorldMap.Instance.World.GetUpperBound(1); }
		}

		public int MapMax_Z
		{
			get { return WorldMap.Instance.World.GetUpperBound(2); }
		}

		public int LocationCount
		{
			get { return WorldMap.Instance.World.Count; }
		}

		public int GameThings
		{
			get { return Everything._everything.Count; }
		}

		private GlobalMonitor() { }
	}
}
